<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>抽奖游戏</title>
    <style>
        table {
            border: 1px solid #ccc;
            border-collapse: collapse;
            margin: 0 auto;
            width: 50%;
        }

        th, td {
            border: 1px solid #ccc;
            width: 100px;
            height: 100px;
        }
    </style>
</head>
<body>
<table>
    <tr>
        <th id="td1">王卓飞</th>
        <th id="td2">韩奕辰</th>
        <th id="td3">韩福临</th>
        <th id="td4">王莹</th>
    </tr>
    <tr>
        <th id="td12">王雷</th>
        <th colspan="2" rowspan="2">
            <label id="result"></label>
            <br/>
            <button onclick="startGame()">开始游戏</button>
        </th>

        <th id="td5">马浩伟</th>
    </tr>
    <tr>
        <th id="td11">徐启超</th>

        <th id="td6">高宇凡星</th>
    </tr>
    <tr>
        <th id="td10">吴豪哲</th>
        <th id="td9">欧阳潘达</th>
        <th id="td8">赵文轩</th>
        <th id="td7">杨成功</th>
    </tr>
</table>
</body>
</html>
<script>
    let index = 1;
    let beforeIndex = 12;
    let jiange = 50;
    let num = 1;
    let timer;
    let randomNum = Math.floor(Math.random() * 50 + 12);

    function startGame() {
        num++;
        let nowObj = document.getElementById('td' + index)
        let beforeObj = document.getElementById('td' + beforeIndex)

        if (num >= randomNum) {
            document.getElementById('result').innerText = beforeObj.innerText
            setTimeout('shan1()',10)
            clearTimeout(timer);
            return;
        }
        if (index < 12) {
            index++;
        } else {
            index = 1;
        }
        if (beforeIndex < 12) {
            beforeIndex++;
        } else {
            beforeIndex = 1;
        }

        nowObj.style.backgroundColor = 'red'
        beforeObj.style.backgroundColor = ''
        jiange += 10;
        timer = setTimeout("startGame()", jiange)
    }

    function shan1() {
        document.getElementById('result').style.color = '#6e4747'
        setTimeout('shan2()', 50)
    }

    function shan2() {
        document.getElementById('result').style.color = '#0df642';
        setTimeout('shan1()', 50)
    }
</script>